package com.furns.dao.impl;

import com.furns.dao.BasicDAO;

import com.furns.dao.MemberDAO;
import com.furns.entity.Member;

/**
 * @Author LuoJiaCheng
 * @ID 2240129126
 * @Version 1.0
 */
public class MemberDAOImpl extends BasicDAO<Member> implements MemberDAO {
    /**
     * 通过用户名返回对应的Member
     * @param username 用户名
     * @return 对应的Member,如果没有该Member,返回null
     */

    @Override
    public Member queryMemberByUsername(String username) {
        String sql="select id,username,password,email from member where username=?";
        Member member = querySingle(sql, Member.class, username);
        return member;
    }

    /**
     * 保存一个用户
     * @param member 传入Member对象
     * @return 返回-1失败，返回其他数字是受影响行数
     */
    @Override
    public int saveMember(Member member) {
        String sql ="insert into member(username,password,email) values(?,?,?)";
        int update = update(sql, member.getUsername(), member.getPassword(), member.getEmail());

        return  update;
    }

    /**
     * 通过用户名和密码返回对应的Member
     * @param username 用户名
     * @param password 密码
     * @return 对应的Member,如果没有该Member,返回null
     */
    @Override
    public Member queryMemberByUsernameAndPassword(String username, String password) {
        String sql ="select id,username,password,email from member where username=? and password=?";
        Member member = querySingle(sql, Member.class, username, password);
        return member;
    }
}
